﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DormMS.IService;
using DormMS.Model;
using Infrastructure.Dao;
using SqlSugar;

namespace DormMS.Service
{
    public class DepartmentService : IDepartmentService
    {
        private SqlSugarClient db;
        /// <summary>
        /// 通过系部名称找系部
        /// </summary>
        /// <param name="search"></param>
        /// <returns></returns>
        public Department getDepartmentByName(string search)
        {
            
            using (db = DbConfig.GetInstance())
            {
                db.CurrentFilterKey = "";
                var model = db.Queryable<Department>().SingleOrDefault(x => x.DepartmentName == search);
                return model;
            }
        }
        /// <summary>
        /// 查找系部
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public List<Department> getDepartmentList()
        {
            
            using (db = DbConfig.GetInstance())
            {
                db.CurrentFilterKey = "";
                var data = db.Queryable<Department>().OrderBy(x => x.Id).ToList();
                return data;
            }
        }
    }
}
